package com.zhang.authoritycenter.controller.oauth;


import com.zhang.authoritycenter.common.model.dao.auth.UserBaseDO;
import com.zhang.authoritycenter.common.model.dto.auth.LoginDTO;
import com.zhang.authoritycenter.common.model.dto.auth.RegisterReqDTO;
import com.zhang.authoritycenter.manager.IOauthManager;
import com.zhang.infrastructure.model.KingHoodResponseVO;
import com.zhang.authoritycenter.common.model.dto.auth.KingHoodPrincipal;
import com.zhang.authoritycenter.common.model.dto.auth.UserDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

/**
 * description
 *
 * @author zhangFanJun
 * @date 2023-12-06 10:42
 **/
@RequiredArgsConstructor
@RestController
public class LoginController {

    private final IOauthManager oauthManager;

    /**
     * 注册
     *
     * @param in 注册入参
     * @return 用户信息
     * @author zfj
     * @date 2023/12/6
     */
    @PostMapping("/register")
    public KingHoodResponseVO<UserBaseDO> register(@RequestBody RegisterReqDTO in) {
        return KingHoodResponseVO.success(oauthManager.register(in));
    }

    /**
     * 登录
     *
     * @param in 登录入参
     * @return 用户信息
     * @author zfj
     * @date 2023/12/6
     */
    @PostMapping("/login")
    public KingHoodResponseVO<KingHoodPrincipal<UserDTO>> login(@RequestBody LoginDTO in) {
        return KingHoodResponseVO.success(oauthManager.login(in));
    }

    /**
     * 注销
     *
     * @return 成功与否
     * @author zfj
     * @date 2023/12/6
     */
    @PostMapping("/out")
    public KingHoodResponseVO<Boolean> out(@RequestHeader("Authorization")String bear) {
        return KingHoodResponseVO.success(oauthManager.logout(bear));
    }

}
